<?php


require_once(DIR_LIB."VsGui".DIR_SEP."vssmartywidget.php");

class VsPager extends VsSmartyWidget {

	private $_totalItemsCount = 0;
	private $_page = 0;
	private $_view = 0;

	function __construct(&$page, $countItems, $view=3) {
		// Ne go zabravqj ina4e nqma $smarty Object
		parent::__construct();

		$this->_template = dirname(__FILE__).DIR_SEP."html".DIR_SEP."vspager.html";

		$this->_totalItemsCount = $countItems;

		//$itemFact->setPager($this);
		//$this->_items = $itemFact->makeItems();

		$this->_page = isset($_GET['pgr']) ? $_GET['pgr'] : 1;
		$this->_view = $view;


		$pagesNum = ($this->_totalItemsCount % $this->_view) ? (intval($this->_totalItemsCount / $this->_view)+1) : $this->_totalItemsCount / $this->_view;
		$this->assign("totalItemsCount", $this->_totalItemsCount); // For Debugging Purposes

		$this->assign("pagesNum", $pagesNum);
		$this->assign("page", $this->_page);

		//$query =  $_SERVER['QUERY_STRING'];
		$query =  "";
		foreach($_GET as $key=>$val) {
			if($key!=='pgr')
				$query .= $key."=".$val."&";
		}
		$query = rtrim($query, "&");

		$this->assign("query", $query);
	}
	//=============================================================================

	function show() {
		return $this->fetch($this->_template);
	}
	//=============================================================================

	function page() { return $this->_page; }
	function view() { return $this->_view; }
	function from() { return $this->_view * ($this->_page-1); }

	function setTotalItemsCount($countItems) {
		$this->_totalItemsCount = $countItems;
	}
}

?>
